﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace Weibo4SharpTest.Service
{
    [TestFixture]
    public class FriendshipTests : WeiboServiceTestBase
    {
        [Test]
        public void can_follow_user()
        {
            var s = GetAuthenticatedService();
            var user = s.UnfollowUser("李开复");

            s = GetAuthenticatedService();
            user = s.FollowUser(Res.UserIdOfKaifuLee);

            AssertResultWasOK(s);
            Assert.IsNotNull(user);
            Assert.AreNotEqual(0, user.Id);
        }

        [Test]
        public void can_unfollower_user()
        {
            var s = GetAuthenticatedService();
            var user = s.FollowUser(Res.UserIdOfKaifuLee);

            s = GetAuthenticatedService();
            user = s.UnfollowUser("李开复");

            AssertResultWasOK(s);
            Assert.IsNotNull(user);
            Assert.AreNotEqual(0, user.Id);
        }

        [Test]
        public void can_get_friendship1()
        {
            var s = GetAuthenticatedService();
            var friendship = s.GetFriendshipInfo(Res.UserIdOfXxfflower);

            AssertResultWasOK(s);
            Assert.IsNotNull(friendship);
            Assert.AreEqual(true, friendship.Target.Following);
        }

        [Test]
        public void can_get_friendship2()
        {
            var s = GetAuthenticatedService();
            var friendship = s.GetFriendshipInfo(Res.UserIdOfXxfflower, Res.UserIdOfKaifuLee);

            AssertResultWasOK(s);
            Assert.IsNotNull(friendship);
            Assert.AreEqual(false, friendship.Target.FollowedBy);
        }

        [Test]
        public void can_verify_friendship()
        {
            var s = GetAuthenticatedService();
            var result = s.VerifyFriendship(Res.UserIdOfXxfflower, Res.UserIdOfKaifuLee);

            AssertResultWasOK(s);
            Assert.IsNotNull(result);
            Assert.IsTrue(result.IsFriend); // kaifu lee is a friend of xxfflower

            result = s.VerifyFriendship(Res.UserIdOfKaifuLee, Res.UserIdOfXxfflower);
            AssertResultWasOK(s);
            Assert.IsNotNull(result);
            Assert.IsFalse(result.IsFriend); // xxfflower is not a friend of kaifu lee
        }
    }
}
